package com.example.springcloudhystix.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/14 0:11
 * @since JDK 1.8
 */
@RestController
public class TestController {

    @RequestMapping("/test")
    @HystrixCommand(fallbackMethod = "methodFallback",
            commandProperties=@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))
    public String testHystixController(){
        return "test,helloword";
    }

    @RequestMapping("/test2")
    @HystrixCommand(fallbackMethod = "methodFallback",
            commandProperties=@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))
    public String test2HystixController() throws Exception{
        Thread.sleep(Long.valueOf("2000"));
        return "test2.helloword";
    }

    @RequestMapping("/test3")
    @HystrixCommand(fallbackMethod = "methodFallback",
            commandProperties=@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))
    public String test3HystixController() throws Exception{
        Thread.sleep(Long.valueOf("800"));
        return "test2.helloword";
    }

    public String methodFallback(){
       return "服务暂时,出了点问题";
    }



}
